import { Module } from "@nestjs/common";
import { UploadController } from "./upload.controller";
import { MulterModule } from "@nestjs/platform-express";
import { diskStorage } from "multer";
import { extname, join } from "path";
import * as process from "process";

@Module({
  imports: [
    MulterModule.register({
      storage: diskStorage({
        destination: join(process.cwd(), "public", "uploads"),
        filename(
          _,
          file: Express.Multer.File,
          callback: (error: Error | null, filename: string) => void
        ) {
          const fileName = `${
            new Date().getTime() + extname(file.originalname)
          }`;
          return callback(null, fileName);
        }
      })
    })
  ],
  controllers: [UploadController]
})
export class UploadModule {}
